package com.example.hyw.szysteam.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.example.hyw.szysteam.POJO.HomeWork;
import com.example.hyw.szysteam.R;

import java.util.ArrayList;

/**
 * Created by HYW on 2018/6/26.
 */

public class HomeWorkAdapter extends ArrayAdapter<HomeWork>{
    private int resource;
    private ArrayList<HomeWork> homeWorks;

    public HomeWorkAdapter(@NonNull Context context, int resource,ArrayList<HomeWork> homeWork) {
        super(context, resource, homeWork);
        this.resource = resource;
        this.homeWorks = homeWork;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        HomeWork homeWork=homeWorks.get(position);
        View view;
        ViewHolder viewHolder;
        if(convertView==null){
            view= LayoutInflater.from(getContext()).inflate(resource,null);
            viewHolder=new ViewHolder();
            viewHolder.testName=view.findViewById(R.id.tv_testname);
            viewHolder.date=view.findViewById(R.id.tv_date);
            view.setTag(viewHolder);
        }else {
            view=convertView;
            viewHolder=(ViewHolder)view.getTag();
        }
        viewHolder.testName.setText(homeWork.getTestName());
        viewHolder.date.setText(homeWork.getDate());
        return view;
    }

    @Nullable
    @Override
    public HomeWork getItem(int position) {
        return homeWorks.get(position);
    }

    class ViewHolder{
        TextView testName;
        TextView date;
    }
}
